Repository navigation
Guard re-entry in rbs test hooks - #3383
Merged
Merged
Conversation
Hooking a core class reopened by the program, like `Integer` or `Hash`, caused infinite recursion, because the hooks call methods that can be hooked themselves (`Hash#[]`, `Integer#<` through `Logger`, ...). The hooks now run their bookkeeping and type checking inside a guard, and hooked methods called inside it call the original method directly. The original method is called outside of the guard, so hooked methods called from it are still type checked. The guard calls its primitives through `bind_call`, and `UnboundMethod#bind_call` itself is never hooked. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes problem 5 of #3369:
rbs testdies withSystemStackErrorwhen the target is a core class reopened by the program, likeIntegerorHash.The generated hook calls methods that can be hooked themselves (
Hash#[]forORIGINAL_METHODS,Integer#<throughLogger,Class#newforArgumentsReturn/CallTrace, the type checker, ...), and nothing guards re-entry.Changes
RBS::Test::Hook.guard). A hooked method called inside the guard calls the original method directly, without type checking.Observer.notify(type checking) inside the guard.Thread.current,Thread#[],Thread#[]=,Hash#[],__send__, ...) throughUnboundMethods captured at load time, which keep pointing to the original definitions after hooking. So the only method that cannot be hooked isUnboundMethod#bind_call;Tester#install!skips it with a log message.setup.rbruns itsTracePointhandler (includinginstall!) inside the guard, sorbs test's own code isn't type checked.Not in scope
RBS_TEST_TARGET=Kernelwith a script reopeningmodule Kernelno longer recurses, but still fails because frame-sensitive methods like__method__get hooked (problem 9 of #3369).🤖 Generated with Claude Code